#!/usr/bin/env python
# encoding: utf-8


"""
@file: tuxiang.py
@time: 2016/10/31 上午10:51
"""
# 图像问题
from mathsolver.functions.base import *
from sympy import sin, cos, tan, pi, cot, symbols, solveset
from mathsolver.functions.sanjiao import sanjiao_utils as su
from mathsolver.functions.budengshi import common_opers as co
from mathsolver.functions.sanjiao.huajian import SanJiaoHuaJian, trig_simplify
import re
from mathsolver.functions.sanjiao.sanjiao_constants import SanJiaoFangXiangKeys
from operator import itemgetter


def simp_trig_info(f_str):
    """
    Noet:f_str是三角函数的字符表示，一定要用字符表示。不能用Sympy符号对象表示，不然它会自动化简。
    获取简单三角函数的信息。形如 y = A*sin(w*x + b) + c。
    返回 (A, 'sin', w*x + b, c) 元组
    :param f_str:
    :return:
    >>> simp_trig_info('cos(3*x) + 5')
    (1, cos, 3*x, 5)
    >>> simp_trig_info('5*cos(3*x + 2) + 5')
    (5, cos, 3*x + 2, 5)
    >>> simp_trig_info('sin(x)')
    (1, sin, x, 0)
    >>> simp_trig_info('cos(x)')
    (1, cos, x, 0)
    """
    f_str = str(f_str)
    trig_p = r'((.*)\*?)?(sin|cos)\((.*)\)(.*)'
    m = re.search(trig_p, f_str)
    _, coef, t_type, arg, c = m.groups()
    if '-' == coef.strip():
        coef = sympify('-1')
    else:
        coef = sympify(coef.replace('*', '')) if coef else sympify('1')
    t_type = type(sympify(t_type + '(1)'))
    arg = sympify(arg)
    c = sympify(c) if c else sympify('0')
    return coef, t_type, arg, c


def trig_arg_collect(arg):
    """
    参数分解因式
    :param arg:
    :return:
    >>> trig_arg_collect('2*x + pi/6')
    (2, pi/12)
    >>> trig_arg_collect('2*x - pi/3')
    (2, -pi/6)
    >>> trig_arg_collect('2*x')
    (2, 0)
    """
    arg = sympify(arg)
    x_symbol = list(arg.free_symbols)[0]
    x_coeff = arg.coeff(x_symbol)
    _, const = co.split_mons_const(arg)
    m = const / x_coeff
    return x_coeff, m


def sin_2_cos(sin_f):
    """
    sin转换为cos
    :param sin_f:
    :return:
    >>> cos_2_sin('sin(x-pi/3)')
    (1, sin, x - pi/3, 0)
    """
    sin_coef, _1, sin_arg, _2 = simp_trig_info(sin_f)
    if _1 == cos:
        return sin_coef, _1, sin_arg, _2
    cos_arg = pi / 2 - sympify(sin_arg)
    cos_coef = sin_coef
    cos_arg_x_coef = cos_arg.coeff('x')
    if cos_arg_x_coef < 0:
        cos_arg = -cos_arg
    return cos_coef, cos, cos_arg, _2


def cos_2_sin(cos_f):
    """
    cos转换为sin
    :param cos_f:
    :return:
    >>> cos_2_sin('-cos(x+pi/6)')
    (1, sin, x - pi/3, 0)
    """
    cos_coef, _1, cos_arg, _2 = simp_trig_info(cos_f)
    if _1 == sin:
        return cos_coef, _1, cos_arg, _2
    sin_arg = pi / 2 - sympify(cos_arg)
    sin_coef = cos_coef
    sin_arg_x_coef = sin_arg.coeff('x')
    if sin_arg_x_coef < 0:
        sin_arg = -sin_arg
        sin_coef = -sympify(sin_coef)
    return sin_coef, sin, sin_arg, _2


# 图像变换首先要转变成同名函数
# y = A1*sin(w1*x + b1) + c -> y = A2*sin(w2*x + b2) + c2
class BianHuan(BaseFunction):
    @staticmethod
    def sin_2_cos(sin_f):
        """
        sin函数转换为cos函数[由于sympy在转换的过程中，有时会将sin转换为cos，所以整个过程要全字符处理]
        :param sin_f:
        :return:
        """
        return ''

    @staticmethod
    def cos_2_sin(cos_f):
        """
        cos转换为sin
        :param cos_f:
        :return:
        """
        return ''

    def solver(self, *args):
        src_fx = args[1]  # 原三角函数
        if isinstance(src_fx, BaseFunc):
            src_fx = BaseEq([src_fx.name, src_fx.expression])
        y1, f1 = src_fx.sympify()
        f1 = trig_simplify(f1)
        t1_coef, t1_type, t1_arg, t1_c = su.simp_trig_info(f1)
        dest_fx = args[0]  # 目标三角函数
        y2, f2 = dest_fx.sympify()
        f2 = trig_simplify(f2)
        t2_coef, t2_type, t2_arg, t2_c = su.simp_trig_info(f2)
        if t1_type != t2_type:  # 首先转变成同名三角函数
            # 方式一都转变成sin函数
            t1_coef, t1_type, t1_arg, t1_c = su.cos_2_sin(f1)
            t2_coef, t2_type, t2_arg, t2_c = su.cos_2_sin(f2)
            if t1_coef * t2_coef < 0:  # 如果转变后两个不同号
                t1_coef, t1_type, t1_arg, t1_c = su.sin_2_cos(f1)
                t2_coef, t2_type, t2_arg, t2_c = su.sin_2_cos(f2)
        # 化成同名函数
        # if t1_type == sin and t2_type == cos:
        #     t1_arg += pi / 2
        #     t1_type = cos
        #     t1_arg = -t1_arg
        #     self.steps.append(['函数%s = %s' % (y1, f1), ' 转变为 %s = %s*%s(%s)%s' % (
        #         y1, t1_coef, str(t1_type), t1_arg, '+ ' + (str(t1_c) if t1_c > 0 else '-' + str(t1_c)))])
        # elif t1_type == cos and t2_type == sin:
        #     t1_arg += pi / 2
        #     t1_type = sin
        #     self.steps.append(['函数%s = %s' % (y1, f1), ' 转变为 %s = %s*%s(%s)%s' % (
        #         y1, t1_coef, str(t1_type), t1_arg, '+ ' + (str(t1_c) if t1_c > 0 else '-' + str(t1_c)))])
        if t1_coef == '1':
            t1_coef_print = ''
        elif t1_coef == '-1':
            t1_coef_print = '-'
        else:
            t1_coef_print = new_latex(t1_coef)
        n_f1_print = r'%s \%s{\left (%s \right )}' % (t1_coef_print, str(t1_type), new_latex(t1_arg)) + (
            new_latex(t1_c) if t1_c else '')
        if t2_coef == '1':
            t2_coef_print = ''
        elif t2_coef == '-1':
            t2_coef_print = '-'
        else:
            t2_coef_print = new_latex(t2_coef)
        n_f2_print = r'%s \%s{\left (%s \right )}' % (t2_coef_print, str(t2_type), new_latex(t2_arg)) + (
            new_latex(t2_c) if t2_c else '')
        self.steps.append(['由题意得原函数y=%s' % n_f1_print, ';目标函数y=%s' % n_f2_print])
        # 确保w1, w2为正数
        t1_arg_coef, t1_arg_fac_c = trig_arg_collect(t1_arg)
        if t1_arg_coef < 0:
            t1_arg = -t1_arg
            t1_coef = -t1_coef
            self.steps.append(['函数%s = %s' % (y1, f1), ' 转变为 %s = %s*%s(%s)%s' % (
                y1, t1_coef, str(t1_type), t1_arg, '+ ' + (str(t1_c) if t1_c > 0 else '-' + str(t1_c)))])
        t2_arg_coef, t2_arg_fac_c = trig_arg_collect(t2_arg)
        if t2_arg_coef < 0:
            t2_arg = -t2_arg
            t2_coef = -t2_coef
            self.steps.append(['函数%s = %s' % (y2, f2), ' 转变为 %s = %s*%s(%s)%s' % (
                y2, t2_coef, str(t2_type), t2_arg, '+ ' + (str(t2_c) if t2_c > 0 else '-' + str(t2_c)))])
        # X轴方向的转换.先压缩/拉伸 在平移
        if t1_arg_coef / t2_arg_coef > 1 and (t1_arg_coef / t2_arg_coef) != 1:
            self.steps.append(['x拉伸为原来', new_latex(t1_arg_coef / t2_arg_coef) + '倍.'])
        elif (t1_arg_coef / t2_arg_coef) != 1:
            self.steps.append(['x压缩为原来', new_latex(t1_arg_coef / t2_arg_coef) + '倍.'])
        if t2_arg_fac_c > t1_arg_fac_c:
            self.steps.append(['向左平移', new_latex(abs(t2_arg_fac_c - t1_arg_fac_c)) + '个单位;'])
        elif t2_arg_fac_c != t1_arg_fac_c:
            self.steps.append(['向右平移', new_latex(abs(t2_arg_fac_c - t1_arg_fac_c)) + '个单位;'])
        # Y轴方向上的变换. 先压缩/拉伸 在平移
        if t2_coef / t1_coef > 0 and (t2_coef / t1_coef) != 1:
            self.steps.append(['y值变为原来', new_latex(t2_coef / t1_coef) + '倍.'])
        elif (t2_coef / t1_coef) != 1:
            self.steps.append(['y值变为原来', new_latex(t2_coef / t1_coef) + '倍.且沿X轴上下翻转.'])
        if t2_c / t2_coef - t1_c / t1_coef > 0:
            self.steps.append(['向上平移', new_latex(abs(t2_c / t2_coef - t1_c / t1_coef)) + '个单位'])
        elif t2_c / t2_coef != t1_c / t1_coef:
            self.steps.append(['向下平移', new_latex(abs(t2_c / t2_coef - t1_c / t1_coef)) + '个单位'])
        self.label.add('三角函数图像的变换')
        return self


# 函数y=sin(2x-\\frac{π}{6})的一条对称轴为()
class DuiChenZhou(BaseFunction):
    def solver(self, *args):
        self.label.add('求三角函数对称轴')
        y_symbol, trig_f = args[0].sympify()
        huajian = SanJiaoHuaJian(verbose=True).solver(trig_f)
        steps = huajian.steps
        simp_f = huajian.output[0].sympify()
        self.steps.append(['函数 %s = %s' % (new_latex(y_symbol), new_latex(trig_f)), ''])
        self.steps.extend(steps)
        self.steps.append([' = ', new_latex(simp_f)])
        trig_mon, _ = co.split_mons_const(simp_f)
        t = su.trig_type(trig_mon)
        if t == sin:
            r = sympify('k*pi + pi/2')
        elif t == cos:
            r = sympify('k*pi')
        else:
            r = sympify('k*pi/2')
        arg = su.trig_arg(trig_mon)
        x_symbol = list(arg.free_symbols)[0]
        x_value = list(solveset(r - arg, symbol=x_symbol))[0]
        self.steps.append(['令 %s = %s，' % (new_latex(arg), new_latex(r)),
                           ' 可得 %s = %s' % (new_latex(x_symbol), new_latex(x_value))])
        self.steps.append(['故图像的对称轴为x = %s' % new_latex(x_value), ' ' + su.print_belong_z('k')])
        self.output.append(BaseZhiXian({'name': '', 'value': [sympify('x'), x_value]}))
        return self


# 对称轴求参 由对称轴得到等式
# Input1 paramer1: 三角函数; paramer2:对称轴
class SanJiaoDuiChengZhouQiuCan(BaseFunction):
    def solver(self, *args):
        self.label.add('已知三角函数的对称轴得到等式')
        y_symbol, f_expr = args[0].sympify()  # 三角函数
        f_expr = trig_simplify(f_expr)
        t_coef, t_type, t_arg, _ = su.simp_trig_info(f_expr)
        _k = sympify('k')
        _kpi = _k * pi
        if t_type == sin:
            eq = [t_arg, _kpi + pi / 2]
        elif t_type == cos:
            eq = [t_arg, _kpi]
        else:
            raise Exception('Type Match Error')
        self.output.append(BaseEqs(eq))
        self.output.append(BaseSymbolValue({_k: S.Intehers}))
        return self


# 函数y=sinxcosx+\\sqrt{3}cos^{2}x-\\frac{\\sqrt{3}}{2}的图象的一个对称中心是()
class DuiChengZhongXin(BaseFunction):
    def solver(self, *args):
        self.label.add('对称中心')
        y_symbol, trig_f = args[0].sympify()
        huajian = SanJiaoHuaJian(verbose=True).solver(trig_f)
        steps = huajian.steps
        simp_f = huajian.output[0].sympify()
        self.steps.append(['函数 %s = %s' % (new_latex(y_symbol), new_latex(trig_f)), ''])
        self.steps.extend(steps)
        self.steps.append([' = ', new_latex(simp_f)])
        trig_mon, _ = co.split_mons_const(simp_f)
        t = su.trig_type(trig_mon)
        if t == sin:
            r = sympify('k*pi')
        elif t == cos:
            r = sympify('pi/2 + k*pi')
        else:
            r = sympify('k*pi/2')
        arg = su.trig_arg(trig_mon)
        x_symbol = list(arg.free_symbols)[0]
        x_value = list(solveset(r - arg, symbol=x_symbol))[0]
        self.steps.append(['令 %s = %s，' % (new_latex(arg), new_latex(r)),
                           ' 可得 %s = %s' % (new_latex(x_symbol), new_latex(x_value))])
        self.steps.append(['故图像的对称中心为(%s, 0)' % new_latex(x_value), ''])
        self.output.append(BaseNumber(x_value))
        return self


# 对称中心求参 输出一个等式组
# Input paramer1:三角函数; paramer2:点(m, n)
class DuiChengZhongXinQiuCan(BaseFunction):
    def solver(self, *args):
        y_symbol, f_expr = args[0].sympify()
        x_point, y_point = args[1].sympify()
        t_coef, t_type, t_arg, t_const = su.simp_trig_info(f_expr)
        eqs = []
        _k = sympify('k')
        _kpi = _k * pi
        if t_type == sin:
            eqs.append([t_arg, _kpi])
            eqs.append([t_const, y_point])
        elif t_type == cos:
            eqs.append([t_arg, _kpi + pi / 2])
            eqs.append([t_const, y_point])
        elif t_type == tan:
            eqs.append([t_arg, _kpi / 2])
            eqs.append([t_const, y_point])
        self.output.append(BaseEqs(eqs))
        self.output.append(BaseSymbolValue({_k: S.Integers}))
        return self


# 三角函数的图像变换 左加右减，上加下减
# paramer1:三角函数表达式; paramer2: 方向; paramer3: 单位
class SanJiaoHanShuTuXiangBianHuan(BaseFunction):
    def solver(self, *args):
        self.label.add('三角函数的图像平移变换')
        arg0 = args[0]
        if isinstance(arg0, BasePoly):
            y_symbol = sympify('y')
            f_expr = arg0.sympify()
        elif isinstance(arg0, BaseEq):
            y_symbol, f_expr = arg0.sympify()
        elif isinstance(arg0, BaseSinEq):
            y_symbol, f_expr = arg0.sympify()
        elif isinstance(arg0, BaseSinFunc):
            y_symbol, f_expr = arg0.sympify()
        else:
            y_symbol = sympify('y')
            f_expr = sympify(arg0)
        direct = args[1]
        if isinstance(args[2], BasePoly):
            unit = args[2].sympify()
        else:
            unit = sympify(args[2])
        sim_f = trig_simplify(f_expr)
        self.steps.append(['由题意得 %s=' % new_latex(y_symbol) + new_latex(sim_f), ''])
        trig_mon, _ = co.split_mons_const(sim_f)
        x_symbol = sympify('x')
        if direct == SanJiaoFangXiangKeys.Left or direct.find('左') >= 0:
            direct_text = '向左'
            sub_f = sim_f.subs(x_symbol, x_symbol + unit)
        elif direct == SanJiaoFangXiangKeys.Right or direct.find('右') >= 0:
            direct_text = '向右'
            sub_f = sim_f.subs(x_symbol, x_symbol - unit)
        elif direct == SanJiaoFangXiangKeys.Up or direct.find('上') >= 0:
            direct_text = '向上'
            sub_f = sim_f + unit
        elif direct == SanJiaoFangXiangKeys.Down or direct.find('下') >= 0:
            direct_text = '向下'
            sub_f = sim_f - unit
        elif direct.find('横坐标') >= 0 and (direct.find('伸长') >= 0 or direct.find('扩大') >= 0):
            direct_text = '横坐标伸长'
            sub_f = sim_f.subs(x_symbol, 1 / unit * x_symbol)
        elif direct.find('横坐标') >= 0 and direct.find('缩短') >= 0:
            direct_text = '横坐标缩短'
            sub_f = sim_f.subs(x_symbol, 1 / unit * x_symbol)
        elif direct.find('纵坐标') >= 0 and (direct.find('伸长') >= 0 or direct.find('扩大') >= 0):
            direct_text = '纵坐标伸长'
            t_coef, t_type, t_arg, t_const = su.simp_trig_info(sim_f)
            t_coef = t_coef * unit
            sub_f = t_coef * t_type(t_arg) + t_const
        elif direct.find('纵坐标') >= 0 and direct.find('缩短') >= 0:
            direct_text = '纵坐标缩短'
            t_coef, t_type, t_arg, t_const = su.simp_trig_info(sim_f)
            t_coef = t_coef * 1 / unit
            sub_f = t_coef * t_type(t_arg) + t_const
        else:
            raise Exception('Type Match Error')
        if direct_text.find('坐标') >= 0:
            self.steps.append(['图像' + direct_text + new_latex(unit) + '个单位', ','])
        else:
            self.steps.append(['图像' + direct_text + '移动' + new_latex(unit) + '个单位', ','])
        self.steps.append(['可得图像对应的函数为y=' + new_latex(sub_f), ''])
        self.output.append(BasePoly(sub_f))
        return self


# SanJiaoHanShuTuXiangBianHuan(verbose=True).solver(BaseEq(['y', 'tan(w*x+pi/4)']), '向右', BasePoly('pi/6'))
# solve_r = BianHuan(verbose=True).solver(BaseEq(['y', 'sin(x)-sqrt(3)*cos(x)']), BaseEq(['y', '2*sin(x)']))
# solve_r = BianHuan(verbose=True).solver(BaseEq(['y', 'sin(x)-sqrt(3)*cos(x)']),
# BaseEq(['y', 'sin(x)+sqrt(3)*cos(x)']))
# for step1, step2 in solve_r.steps:
#     print step1, step2


# 已知函数的相邻的对称轴求参数
# x=m, x=n 是y = A*sin(w*x + a) + h 或者 y = A*cos(w*x + a) + h两条对称轴
# 则 T = 2*|m-n|
# 列出含三个等式的方程组 T = |m-n|; T = 2*pi/Abs|w|;w*m + a = pi/2+ k*pi(sin) 或者 w*m + a = k*pi(cos)
# Input paramer1:三角函数; paramer2:对称轴1; paramer3:对称轴2
class XiangLinDuiChengZhouQiuCan(BaseFunction):
    def solver(self, *args):
        y_symbol, trig_f = args[0].sympify()
        _, symmetry_axis1 = args[1].sympify()  # 对称轴1
        _, symmetry_axis2 = args[2].sympify()  # 对称轴2
        x_symbol = sympify('x')
        sim_trig_f = trig_simplify(trig_f)
        _1, t_type, t_arg, _2 = su.simp_trig_info(sim_trig_f)
        x_coef = sympify(t_arg).coeff(x_symbol)
        x_coef_param_symb = list(x_coef.free_symbols)[0]
        const_params = list(FiniteSet(*trig_f.free_symbols) - FiniteSet(x_symbol, x_coef_param_symb))
        if const_params:  # 如果常量是个参数
            const_param = const_params[0]
        else:
            const_param = None
        self.steps.append(
            ['因为直线' + args[1].printing() + '和' + args[2].printing(),
             '是函数' + args[0].printing() + ' 两条相邻的对称轴'])
        cond_cycle = 2 * abs(symmetry_axis1 - symmetry_axis2)  # 求出周期
        eqs = []
        k_symbol = sympify('k')
        if t_type in [sin, cos]:
            cycle_value = 2 * pi / abs(x_coef)
        elif t_type in [tan, cot]:
            cycle_value = pi / abs(x_coef)
        else:
            raise Exception('illegality trig function')
        t_arg_sub = t_arg.subs(x_symbol, symmetry_axis1)
        if t_type == sin:
            op_value = pi / 2 + k_symbol * pi
        elif t_type == cos:
            op_value = k_symbol * pi
        eqs.append([cycle_value, cond_cycle])
        eqs.append([t_arg_sub, op_value])
        params_valu_list = co.isolve_eqs(BaseEqs(eqs), [x_coef_param_symb, const_param])
        single_symbs_values = co.syms_set_to_single_dict(params_valu_list)
        x_coef_param_values = single_symbs_values[x_coef_param_symb]
        const_param_values = single_symbs_values[const_param]
        self.steps.append(
            ['求得%s = %s' % (new_latex(x_coef_param_symb), new_latex(FiniteSet(*x_coef_param_values))), '对应' + new_latex(
                const_param) + '=' + new_latex(FiniteSet(*const_param_values))])
        # self.output.append(BaseSymbolValue(co.single_dict_2_tuple_dict(single_symbs_values)))
        if self.search(x_coef_param_symb):  # 如果有取值范围
            coef_param_intl = self.search(x_coef_param_symb)
            params_valu_list = filter(lambda _: _[0][1] in coef_param_intl, params_valu_list)
        if self.search(const_param):
            const_param_intl = self.search(const_param)
            params_valu_list = map(lambda _: (_[0], (_[1][0], su.expr_value_list(_[1][1], const_param_intl)[0])),
                                   params_valu_list)
        # self.output.append(BaseSymbolValue(co.syms_set_to_tuple_dict(params_valu_list)))
        single_symbs_values = co.syms_set_to_single_dict(params_valu_list)
        x_coef_param_values = single_symbs_values[x_coef_param_symb]
        const_param_values = single_symbs_values[const_param]
        self.steps.append(
            ['所以%s = %s' % (new_latex(x_coef_param_symb), new_latex(FiniteSet(*x_coef_param_values))), '; ' + new_latex(
                const_param) + '=' + new_latex(FiniteSet(*const_param_values))])
        self.output.append(BaseSymbolValue(single_symbs_values))
        return self


# 求两个三角函数的对称中心
# style1 Input paramer1: 函数1; paramer2:函数2
class LiangSanJiaoHanShuDuiChengZhongXin(BaseFunction):
    def solver(self, *args):
        self.label.add('求两个三角函数的对称中心')
        arg1, arg2 = args
        arg1 = list(co.flatten([arg1.sympify()]))
        arg2 = list(co.flatten([arg2.sympify()]))
        if len(arg1) == 1:
            # f_symbol = 'f'
            f_expr = arg1[0]
        else:
            f_symbol, f_expr = arg1
        if len(arg2) == 1:
            # g_symbol = 'g'
            g_expr = arg2[0]
        else:
            g_symbol, g_expr = arg2
        _x = sympify('x')
        f_simp = trig_simplify(f_expr)
        g_simp = trig_simplify(g_expr)
        f_coef, f_type, f_arg, f_const = su.cos_2_sin(f_simp)
        g_coef, g_type, g_arg, g_const = su.cos_2_sin(g_simp)
        _f_arg_x_coef = f_expr.coeff(_x)
        _g_arg_x_coef = g_expr.coeff(_x)
        if not (f_coef == g_coef and _f_arg_x_coef == _g_arg_x_coef):
            f_coef, f_type, f_arg, f_const = su.sin_2_cos(f_simp)
            g_coef, g_type, g_arg, g_const = su.sin_2_cos(g_simp)
            _f_arg_x_coef = f_expr.coeff(_x)
            _g_arg_x_coef = g_expr.coeff(_x)
        if not (f_coef == g_coef and _f_arg_x_coef == _g_arg_x_coef):
            raise Exception('Can not solve the question')
        _a, _b = symbols('a, b')
        from mathsolver.functions.hanshu.duicheng_jiexishi import ZhongXingDuiChengQiuJieXiShi
        _, f2_expr = ZhongXingDuiChengQiuJieXiShi().solver(
            BaseEq(['y', f_expr]), BasePoint({'name': '', 'value': (_a, _b)})).output[0].sympify()
        from mathsolver.functions.sanjiao.sanjiaohanchuchonghe import SanJiaoHanShuChongHe
        eqs = SanJiaoHanShuChongHe().solver(BaseEq(['y1', f2_expr]), BaseEq(['y2', g_expr])).output[0]
        param_symbs = list(set(co.eqs_symbs(eqs.sympify())) - {'k'})
        param_values = co.isolve_eqs(eqs, param_symbs)
        symcenter = map(itemgetter(1), param_values[0])
        _p = BasePoint({'value': symcenter, 'name': 'P'})
        self.steps.append(
            ['函数:' + BaseEq(['f', f_expr]).printing(),
             '和函数:' + BaseEq(['f', g_expr]).printing() + '关于点' + _p.printing() + '对称.' + su.print_belong_z('k')])
        self.output.append(_p)
        return self


# 三角函数对称轴/中心相同求参数
# style1 Input paramer1: 函数1; paramer2: 函数2 Output:参数值
class TwoTrigsDuiChengZhongXinXiangDengQiuCan(BaseFunction):
    def solver(self, *args):
        self.label.add('三角函数对称轴相同求参数')
        arg1, arg2 = args
        _, f1 = arg1.sympify()
        _, g1 = arg2.sympify()
        _x = sympify('x')
        f_coef, f_type, f_arg, f_const = su.simp_trig_info(f1)
        g_coef, g_type, g_arg, g_const = su.simp_trig_info(g1)
        f2 = f_type(f_arg)
        g2 = g_type(g_arg)
        from mathsolver.functions.sanjiao.sanjiaohanchuchonghe import SanJiaoHanShuChongHe
        eqs = SanJiaoHanShuChongHe().solver(BaseEq(['y1', f2]), BaseEq(['y2', g2])).output[0]
        symbs = list((f2.free_symbols | g2.free_symbols) - {_x})
        param_values = co.isolve_eqs(eqs, symbs)[0]
        self.steps.append(['由题意可知:', BaseEqs(param_values).printing()])
        self.output.append(BaseSymbolValue(dict(param_values)))
        return self


if __name__ == '__main__':
    pass
    # print '--------SanJiaoHanShuTuXiang--------'
    # solve_r = XiangLinDuiChengZhouQiuCan()
    # solve_r.known[sympify('w')] = Interval(0, S.Infinity)
    # solve_r.known[sympify('a')] = Interval(0, pi)
    # print solve_r.solver(BaseEq(['y', 'sin(w*x + a)']), BaseEq(['x', 'pi/4']),
    #                      BaseEq(['x', '5*pi/4'])).output[0].sympify()
    # g = SanJiaoHanShuTuXiangBianHuan().solver(BaseEq(['f', '3*sin(2*x - pi/4)']), '向左', BasePoly('pi/4')).output[
    #     0].sympify()
    # g = SanJiaoHanShuTuXiangBianHuan().solver(BaseEq(['f', g]), '向下', BasePoly('4')).output[
    #     0].sympify()
    # _solve = LiangSanJiaoHanShuDuiChengZhongXin().solver(BaseEq(['f', '3*sin(2*x - pi/4)']), BaseEq(['g', g]))
    # for s1, s2 in _solve.steps:
    #     print s1, s2
    # _solve = TwoTrigsDuiChengZhongXinXiangDengQiuCan().solver(BaseEq(['f(x)', '3*sin(w*x - pi/6)']),
    #                                                           BaseEq(['g(x)', '2*cos(2*x + h)+1']))

    _solve = BianHuan().solver(BaseEq(['f', '((cos(x))**(2)-(sin(x))**(2))/(2)']),
                               BaseEq(['g', '(1)/(2)*sin(2*x)-(1)/(4)']))
